/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplesprite;

/**
 *
 * @author shohdi
 */


import java.awt.*;
import javax.swing.*;



public class Sprite extends Object {
    
    private ImageEntity entity;
    protected Point pos;
    protected Point vel;
    protected double rotRate;
    protected int currentState;
    
    
    Sprite(JFrame a,Graphics2D g2d)
    {
        entity = new ImageEntity(a);
        entity.setGraphics(g2d);
        entity.setAlive(false);
        pos = new Point(0,0);
        vel = new Point(0,0);
        rotRate= 0.0;
        currentState = 0;
    }
    
    
    public void load(String filename)
    {
        entity.load(filename);
        
    }
    
    
    public void transform()
    {
        entity.setX(pos.x);
        entity.setY(pos.y);
        entity.transform();
    }
    
    public void draw()
    {
        entity.g2d.drawImage(entity.image, entity.at,entity.frame);
        
    }
    
    
    public void drawBounds(Color c)
    {
        entity.g2d.setColor(c);
        entity.g2d.draw(getBounds());
        
    }
    
    
    public void updatePosition()
    {
        pos.x += vel.x;
        pos.y += vel.y;
        
    }
    
    
    public double rotationRate (){return rotRate;}
    public void setRotationRate(double rate){this.rotRate = rate;}
    public void updateRotation()
    {
        setFaceAngle(faceAngle() + rotRate);
        if (faceAngle()<0)
            setFaceAngle(rotRate);
        else if (faceAngle()>360)
            setFaceAngle(360 - rotRate);
        
        
        
        
    }
    
    public int state(){return currentState;}
    public void setState (int state){this.currentState = state;}
    
    
    public Rectangle getBounds(){return entity.getBounds();}
    
    public Point position(){return this.pos;}
    public void setPosition(Point pos){this.pos = pos;}
    
    public Point velocity (){return this.vel;}
    public void setVelocity(Point vel){this.vel = vel;}
    
    public Point center (){
        int x = (int)entity.getCenterX();
        int y = (int)entity.getCenterY();
        return new Point(x,y);
    }
    
    
    public boolean alive(){
        return entity.isAlive();
    }
    public void setAlive(boolean alive)
    {
        entity.setAlive(alive);
        
    }
    
    
    
    public double faceAngle()
    {
        return entity.getFaceAngle();
    }
    
    
    public void setFaceAngle (double angle)
    {
        entity.setFaceAngle(angle);
        
    }
    
    public void setFaceAngle (float angle)
    {
        entity.setFaceAngle((double)angle);
        
    }
    
    
    public void setFaceAngle (int angle)
    {
        entity.setFaceAngle((double)angle);
        
    }
    
    
    
    public double moveAngle()
    {
        return entity.getMoveAngle();
    }
    
    
    public void setMoveAngle(double angle)
    {
        entity.setMoveAngle(angle);
        
    }
    
    public void setMoveAngle(float angle)
    {
        entity.setMoveAngle((double)angle);
        
    }
    
    
    public void setMoveAngle(int angle)
    {
        entity.setMoveAngle((double)angle);
        
    }
    
    
    
    
    
}
